package id.web.faisalabdillah.xtimesheet.services.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import id.web.faisalabdillah.xtimesheet.dao.IHolidaysDao;
import id.web.faisalabdillah.xtimesheet.domain.HolidaysEvent;
import id.web.faisalabdillah.xtimesheet.services.IHolidaysService;

@Service
@Transactional(readOnly=true)
public class HolidaysServiceImpl implements IHolidaysService {

	@Autowired
	private IHolidaysDao holidaysDao;
	
	@Override
	@Transactional(readOnly=false)
	public boolean insert(HolidaysEvent events) {
		try {
			holidaysDao.insert(events);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		
	}

	@Override
	@Transactional(readOnly=false)
	public boolean update(HolidaysEvent events) {
		try {
			holidaysDao.update(events);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		
	}

	@Override
	@Transactional(readOnly=false)
	public boolean delete(long id) {
		try {
			holidaysDao.delete(findById(id));
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		
	}

	@Override
	public HolidaysEvent findById(long id) {
		return holidaysDao.findById(id);
	}

	@Override
	public List<HolidaysEvent> findByDesc(String param) {
		return holidaysDao.findByDesc(param);
	}

	@Override
	public List<HolidaysEvent> findAll() {
		return holidaysDao.findAll();
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IHolidaysService#findBetweenDate(java.util.Date, java.util.Date)
	 */
	@Override
	public List<HolidaysEvent> findBetweenDate(Date first, Date after) {
		return holidaysDao.findBetweenDate(first, after);
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IHolidaysService#sizeAll()
	 */
	@Override
	public int sizeAll() {
		return holidaysDao.sizeAll();
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IHolidaysService#sizeBetweenDate(java.util.Date, java.util.Date)
	 */
	@Override
	public int sizeBetweenDate(Date before, Date after) {
		return holidaysDao.sizeBetweenDate(before, after);
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IHolidaysService#sizeByParams(java.lang.Object)
	 */
	@Override
	public int sizeByParams(Object param) {
		return holidaysDao.sizeByParams(param);
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IHolidaysService#findAllPaged(int, int)
	 */
	@Override
	public List<HolidaysEvent> findAllPaged(int first, int max) {
		return holidaysDao.findAllPaged(first, max);
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IHolidaysService#findByDescPaged(java.lang.String, int, int)
	 */
	@Override
	public List<HolidaysEvent> findByDescPaged(String param, int first, int max) {
		return holidaysDao.findByDescPaged(param, first, max);
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IHolidaysService#findBetweenDatePaged(java.util.Date, java.util.Date, int, int)
	 */
	@Override
	public List<HolidaysEvent> findBetweenDatePaged(Date before, Date after,
			int first, int max) {
		return holidaysDao.findBetweenDatePaged(before, after, first, max);
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.IHolidaysService#findByDate(java.util.Date)
	 */
	@Override
	public HolidaysEvent findByDate(Date date) {
		return holidaysDao.findByDate(date);
	}

}
